package com.zyh.utils;

import com.alibaba.fastjson2.JSONObject;
import com.zyh.domain.Student;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * @author cyrus
 */
public class RequestUtils {
    public static <T> T getReqJsonBody(HttpServletRequest req, Class<T> objectClass) throws IOException {
        BufferedReader reader = req.getReader();
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
        return JSONObject.parseObject(sb.toString(), objectClass);
    }
}
